package transform.app.editors.table.edit;

import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TextCellEditor;

import transform.config.Cost;

public class HighCostEditingSupport extends EditingSupport {
	
	private TableViewer viewer;
	
	public HighCostEditingSupport(TableViewer viewer) {
		super(viewer);
		this.viewer = viewer;
	}

	@Override
	protected CellEditor getCellEditor(Object element) {
		return new TextCellEditor(viewer.getTable());
	}

	@Override
	protected boolean canEdit(Object element) {
		return true;
	}

	@Override
	protected Object getValue(Object element) {
		return String.valueOf(((Cost)element).getHighCost());
	}

	@Override
	protected void setValue(Object element, Object value) {
		
		((Cost)element).setHighCost(Integer.valueOf((String)value));
		viewer.refresh();
	}
}
